from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import time

browser = webdriver.Firefox()
browser.get('http://192.168.1.209:8085/')
# browser.set_window_size(1900,500)
#点击红包
red = browser.find_element_by_id('red-box')
red.click()
browser.find_element_by_link_text('取消').click()
#跳转到 立即登录页面
#browser.find_element_by_link_text('立即登录').click()
#弹出窗口的 确定 取消  警告窗口也是这样
# confirm = browser.switch_to.alert
# confirm.accept()
# confirm.dismiss()

#滚动到底部
browser.execute_script("document.documentElement.scrollTop=10000")

#隐藏红包 不然点击不了下边的关闭
browser.execute_script("document.getElementById('red-box').hidden = true")
#关闭广告
ad = browser.find_element_by_class_name('close-box')
if ad.is_enabled():
    ad.click()

wode = browser.find_element_by_link_text('我的')
wode.click()

browser.execute_script("document.documentElement.scrollTop=10000")

login = browser.find_element_by_id('login_a')
login.click()
alert = browser.switch_to.alert
queding = browser.find_element_by_class_name('weui_btn_dialog ')
tishi = browser.find_element_by_class_name('weui_dialog_bd ')
assert tishi.text == '请输入用户名或者手机号'
assert queding.text == '确定'
queding.click()

username = browser.find_element_by_id('username')
username.send_keys('18300001108')
password = browser.find_element_by_id('password')
password.send_keys('abcd1234')
time.sleep(5)
login.click()

browser.implicitly_wait(5)

#充值
chongzhi = browser.find_element_by_id('cz-btn')
chongzhi.click()

money = browser.find_element_by_id('money')
money.send_keys(4000)

chongzhiqueding = browser.find_element_by_css_selector('.name_text>input')
chongzhiqueding.click()

EC.element_to_be_clickable(browser.find_element_by_link_text('短信获取'))
duanxin = browser.find_element_by_link_text('短信获取')
time.sleep(5)
duanxin.click()
browser.implicitly_wait(10)
while True:
    val = browser.find_element_by_id('J-validateCode2').get_attribute('value')
    if val and len(val) > 5:
        break
    else:
        time.sleep(3)
pass

browser.find_element_by_id('J-payPwd_BindingPay').send_keys('abcd@1234')
finish = browser.find_element_by_css_selector("button.btn-danger")
finish.click()










